﻿using System.Collections.Generic;
using ServiceStack.Text;

namespace Framework.Library.Core.Utils.Json
{
    public class JsonHelper
    {
        public static string ToJSON(object obj)
        {
            return JsonSerializer.SerializeToString(obj);
        }

        public static T ToObj<T>(string jsonString) where T : class, new()
        {
            return JsonSerializer.DeserializeFromString(jsonString, typeof (T)) as T;
        }

        public static List<T> ToList<T>(string jsonString) where T : class, new()
        {
            var lst = JsonSerializer.DeserializeFromString<List<T>>("[" + jsonString + "]");
            return lst;
        }
    }
}